package com.szt.sy.service.system.button;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.szt.sy.entity.system.Button;
import com.szt.sy.mapper.system.ButtonMapper;

/***
 * 按钮服务
 * 
 * @author wwy
 *
 */
@CacheConfig(cacheNames = "buttonCache")
@Service
@Transactional(rollbackFor = RuntimeException.class)
public class ButtonService extends ServiceImpl<ButtonMapper, Button> {
	
	@Autowired
	private ButtonMapper fhbuttonMapper;
	
	/**
	 * 新增
	 *
	 * @param pd
	 * @throws Exception
	 */
	@CacheEvict(allEntries = true)
	public void save(Button entity) throws Exception {
		
		fhbuttonMapper.insert(entity);
	}
	
	/**
	 * 删除
	 *
	 * @param pd
	 * @throws Exception
	 */
	@CacheEvict(allEntries = true)
	public void delete(String id) throws Exception {
		fhbuttonMapper.deleteById(id);
	}
	
	/**
	 * 修改
	 *
	 * @param pd
	 * @throws Exception
	 */
	@CacheEvict(allEntries = true)
	public void edit(Button entity) throws Exception {
		fhbuttonMapper.updateById(entity);
	}
	
	/**
	 * 列表
	 *
	 * @param page
	 * @throws Exception
	 */
	@Cacheable
	public Page<Button> list(Page<Button> page, Map<String, Object> map) throws Exception {
		page.setRecords(fhbuttonMapper.datalistPage(page, map));
		return page;
	}
	
	/**
	 * 列表(全部)
	 *
	 * @param pd
	 * @throws Exception
	 */
	@Cacheable
	public List<Button> listAll(Map<String, Object> map) throws Exception {
		return fhbuttonMapper.listAll(map);
	}
	
	/**
	 * 通过id获取数据
	 *
	 * @param pd
	 * @throws Exception
	 */
	@Cacheable
	public Button findById(String id) throws Exception {
		return fhbuttonMapper.selectById(id);
	}
	
	/**
	 * 批量删除
	 *
	 * @param ArrayDATA_IDS
	 * @throws Exception
	 */
	@CacheEvict(allEntries = true)
	public void deleteAll(String[] ids) throws Exception {
		fhbuttonMapper.deleteBatchIds(Arrays.asList(ids));
	}
	
	/**
	 * 获取数据记录条数
	 *
	 * @param id
	 * @throws Exception
	 */
	@Cacheable
	public Integer findCount() throws Exception {
		return fhbuttonMapper.selectCount(new EntityWrapper<Button>());
	}
}
